//package com.yuntsg.subject_database.entity;
//
//import cn.hutool.db.Db;
//
//import java.io.IOException;
//import java.net.InetAddress;
//import java.sql.SQLException;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.concurrent.ConcurrentHashMap;
//
//// 此部分为把默认数据插入表中。
//public class Table {
//    public static void main(String[] args) throws SQLException, IOException {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        long t0 = System.currentTimeMillis();
//
//        String uniteTable = "scholar_23_05.result_core_paper_unite_test";
//        String ruleTable = "scholar.rule_unit_0107";
//        String resultTable = "scholar.data_auth_same_data_test";
//        String saveTable = "scholar.result_subject_database";
//        String fuDanTable = "scholar.help_fudan_hospital_ranking_list_2020";
//        String jourTable = "scholar.help_jour_relational_table";
//        String duiYingTable = "scholar.help_fudan_hospital_specialist_journal";
//        String speciaTable = "scholar.help_fudan_hospital_specialist";
//        String nsfcTable = "scholar.data_fund_zhang_2021_10_26";
//        String nameTable = "scholar.result_auth_same_name_320w";
//
//        if (InetAddress.getLocalHost().getHostName().equals("localhost.localdomain")) {
//            uniteTable = "speciallist_23_02_03.result_core_paper_unite";
//            resultTable = "scholar.data_auth_same_data";
//            nameTable = "scholar.result_auth_same_name";
//            System.out.println("---使用服务器上的表---");
//        }
//        Db.use().execute("truncate table " + saveTable);
//
//        String limit = "";
////        String limit = " limit 1";
//        Integer onePageNum = 1000;
//
//        // auth: ["39628Łłqiansuyun","173090Łłqiansuyun","207861Łłqiansuyun"] -> 39628Łłqiansuyun = id ; 173090Łłqiansuyun = id ; 207861Łłqiansuyun = id 即三个作者同属于一个自增主键号。
//        Map<String, Integer> authAndAuthIdMap = new ConcurrentHashMap<>();
//        Map<String, List<String>> authIdAndAuthMap = Unit.readAuthIdTable(nameTable, onePageNum, "auth", limit, "id", authAndAuthIdMap, true);
//        System.out.println(format.format(new Date()) + " ① authAndAuthIdMap.size()：" + authAndAuthIdMap.size());
//        Utils.printMemory();
//
//        // 获取标准的单位名称以及标准的部门名称，建成Map，结构为：类型（hosp,univ,dept），自由的词，对应标准的词（top、lower、anyContain、mustExclude）
//        Map<String, Map<String, Utils.TopLower>> ruleMap = new ConcurrentHashMap<>();//类型、自由词、规范后的词（两个） univ -> 四川轻化工大学 -> (top=四川轻化工大学, lower=, anyContain=[], mustExclude=[])
//        Utils.getStandardUnit(ruleTable, ruleMap);
//        System.out.println(format.format(new Date()) + " ② ruleMap.size()：" + ruleMap.size());
//        Utils.printMemory();
//
//        // 获取国自然科学基金数据，结构为：单位；作者、信息List
//        String fundField = "var2`,`year`,`var7`,`var5`,`var6";
//        Map<String, Map<String, List<Unit.NsfcInfo>>> nsfcInfoMap = Unit.readNsfcTable(nsfcTable, onePageNum, fundField, limit, "id", ruleMap, false);
//        System.out.println(format.format(new Date()) + " ③ nsfcInfoMap.size()：" + nsfcInfoMap.size());
//        Utils.printMemory();
//
//        // 以下为需要提前加载到内存的数据，实时计算时，只需要调用setDept（期刊科室）和setJour（基于期刊）即可。
//        Map<String, List<String>> specialistAndDeptListMap = Word.getSpecialistMap(speciaTable); // 复旦专科以及相对应的该专科在发文论文时的中、英文写法集合，加入Map时统一转为小写。
//        System.out.println(format.format(new Date()) + " ④ specialistAndDeptListMap.size()：" + specialistAndDeptListMap.size());
//        Utils.printMemory();
//
//        Map<String, List<Integer>> specialistAndJourListMap = Word.getDuiYingMap(duiYingTable); // 复旦专科以及相对应的该专科所包含的期刊id号集合
//        System.out.println(format.format(new Date()) + " ⑤ specialistAndJourListMap.size()：" + specialistAndJourListMap.size());
//        Utils.printMemory();
//
//        Map<String, Map<String, Double>> fuDanSpecialistMap = Word.readFuDanRank(fuDanTable); // 复旦的专科声誉，结构为专科名称、医院名称、医院得分
//        System.out.println(format.format(new Date()) + " ⑥ fuDanSpecialistMap.size()：" + fuDanSpecialistMap.size());
//        Utils.printMemory();
//
//        Map<String, Map<String, Word.RankScore>> rankScoreMap = Word.getUnitRank(ruleTable, fuDanSpecialistMap);// 排名（世界大学、世界医院、中国大学、中国医院以及复旦医院排行榜中的医院）的相关得分
//        System.out.println(format.format(new Date()) + " ⑦ rankScoreMap.size()：" + rankScoreMap.size());
//        Utils.printMemory();
//
//        Map<Integer, String> jourIdAndNameMap = Word.getJourMap(jourTable); // 期刊的唯一ID号与期刊的名称
//        System.out.println(format.format(new Date()) + " ⑧ jourIdAndNameMap.size()：" + jourIdAndNameMap.size());
//        Utils.printMemory();
//
//        Map<Integer, Integer> pmidAndAidMap = new ConcurrentHashMap<>();
//        Map<Integer, List<Integer>> jourIdAndAidMap = new ConcurrentHashMap<>(); // 与期刊ID相对应的所有的论文aId的集合
//        Map<Integer, byte[]> allArticleInfoMap = Word.readArticleTable(uniteTable, onePageNum, limit, "id", jourIdAndAidMap, pmidAndAidMap, true); // 所有的论文aId及对应的信息
//        System.out.println(format.format(new Date()) + " ⑨ allArticleInfoMap.size()：" + allArticleInfoMap.size());
//        Utils.printMemory();
//
//        Map<String, Unit.EnAuthAndCnAuth> originalAuthMap = new ConcurrentHashMap<>();
//        Map<Integer, List<byte[]>> aIdAndDataInfoMap = Word.readDeptTable(resultTable, onePageNum, limit, "id", "aid`,`result", allArticleInfoMap, ruleMap, originalAuthMap, true); // aId与info（即含有"result"实体类的，内含有原始信息的对应关系，用于查询是否包含科室信息。）
//        System.out.println(format.format(new Date()) + " ⑩ aIdAndDataInfoMap.size()：" + aIdAndDataInfoMap.size());
//        Utils.printMemory();
//
//
//        // 当前年，加上当前月乘以系数0.083，比如，2022年1月份，为2022.083。2022年12月份，为2022.996。因只统计近6年的数据，所以，开始年等于当前年减去6。
//        double startYear = (Calendar.getInstance().get(Calendar.YEAR) + ((Calendar.getInstance().get(Calendar.MONTH) + 1) * 0.083)) - 6;
//        int top = 100;
//        List<Utils.TableField> tableList = Collections.synchronizedList(new ArrayList<Utils.TableField>());
//        boolean isInsertTable = true; // 是否对结果进行插表，在这里插表（true）。
//
//        // 处理基于期刊学科部分
//        for (Map.Entry<String, List<Integer>> entry : specialistAndJourListMap.entrySet()) {
//            List<Integer> jidList = entry.getValue();
//            String code = "基于期刊学科";
//            String specialist = entry.getKey();
//            if (rankScoreMap.containsKey(specialist)) {
//                Map<String, Word.RankScore> rankScore = rankScoreMap.get(specialist);
//                Map<String, Utils.TypeAndRank> unitOrAuthAndRankMap = new ConcurrentHashMap<>();
//                Set<Integer> articleAidSet = Word.getJourArticleIdList(jidList, jourIdAndAidMap);
//                Word.wordOut(saveTable, articleAidSet, rankScore, startYear, top, code, specialist, 0, allArticleInfoMap, authAndAuthIdMap, unitOrAuthAndRankMap, authIdAndAuthMap, aIdAndDataInfoMap, ruleMap, tableList, isInsertTable, originalAuthMap);
//                System.out.println(format.format(new Date()) + " " + code + " Specialist: " + specialist + " ---热点--- articleIdList.size(): " + articleAidSet.size());
//                Unit.readUnivTable(saveTable, allArticleInfoMap, nsfcInfoMap, ruleMap, authAndAuthIdMap, aIdAndDataInfoMap, unitOrAuthAndRankMap, articleAidSet, tableList, isInsertTable, originalAuthMap);
//                System.out.println(format.format(new Date()) + " " + code + " Specialist: " + specialist + " ---单位--- articleIdList.size(): " + articleAidSet.size());
//                Unit.readAuthTable(allArticleInfoMap, nsfcInfoMap, ruleMap, authAndAuthIdMap, saveTable, authIdAndAuthMap, aIdAndDataInfoMap, unitOrAuthAndRankMap, articleAidSet, tableList, isInsertTable, originalAuthMap);
//                System.out.println(format.format(new Date()) + " " + code + " Specialist: " + specialist + " ---作者--- articleIdList.size(): " + articleAidSet.size());
//            }
//        }
//        long t1 = System.currentTimeMillis();
//        System.out.println(format.format(new Date()) + " 处理基于期刊学科部分结束，用时：" + Utils.Arith.div((t1 - t0), 60000) + " 分钟。");
//
//        // 处理基于作者部门部分
//        for (Map.Entry<String, List<String>> entry : specialistAndDeptListMap.entrySet()) {
//            List<String> deptList = entry.getValue();
//            String specialist = entry.getKey();
//            String code = "基于作者部门";
//            if (rankScoreMap.containsKey(specialist)) {
//                Map<String, Word.RankScore> rankScore = rankScoreMap.get(specialist);
//                Map<String, Utils.TypeAndRank> unitOrAuthAndRankMap = new ConcurrentHashMap<>();
//                Set<Integer> articleAidSet = Word.getArticleIdList(deptList, aIdAndDataInfoMap);
//                Word.wordOut(saveTable, articleAidSet, rankScore, startYear, top, code, specialist, 0, allArticleInfoMap, authAndAuthIdMap, unitOrAuthAndRankMap, authIdAndAuthMap, aIdAndDataInfoMap, ruleMap, tableList, isInsertTable, originalAuthMap);
//                System.out.println(format.format(new Date()) + " " + code + " Specialist: " + specialist + " ---热点--- articleIdList.size(): " + articleAidSet.size());
//                Unit.readUnivTable(saveTable, allArticleInfoMap, nsfcInfoMap, ruleMap, authAndAuthIdMap, aIdAndDataInfoMap, unitOrAuthAndRankMap, articleAidSet, tableList, isInsertTable, originalAuthMap);
//                System.out.println(format.format(new Date()) + " " + code + " Specialist: " + specialist + " ---单位--- articleIdList.size(): " + articleAidSet.size());
//                Unit.readAuthTable(allArticleInfoMap, nsfcInfoMap, ruleMap, authAndAuthIdMap, saveTable, authIdAndAuthMap, aIdAndDataInfoMap, unitOrAuthAndRankMap, articleAidSet, tableList, isInsertTable, originalAuthMap);
//                System.out.println(format.format(new Date()) + " " + code + " Specialist: " + specialist + " ---作者--- articleIdList.size(): " + articleAidSet.size());
//            }
//        }
//        long t2 = System.currentTimeMillis();
//        System.out.println(format.format(new Date()) + " 处理基于作者部门部分结束，用时：" + Utils.Arith.div((t2 - t1), 60000) + " 分钟。");
//
//        // 这里处理的是单本的期刊
//        int jour = 0;
//        for (Map.Entry<Integer, String> entry : jourIdAndNameMap.entrySet()) {
//            jour++;
//            List<Integer> jidList = new ArrayList<>();
//            jidList.add(entry.getKey());
//            String code = "基于期刊学科";
//            String specialist = "期刊名称==" + entry.getValue();
//            if (rankScoreMap.containsKey("journal")) {
//                Map<String, Word.RankScore> rankScore = rankScoreMap.get("journal");
//                Map<String, Utils.TypeAndRank> unitOrAuthAndRankMap = new ConcurrentHashMap<>();
//                Set<Integer> articleAidSet = Word.getJourArticleIdList(jidList, jourIdAndAidMap);
//                System.out.println(format.format(new Date()) + " " + code + " 第: " + jour + " 个，总" + jourIdAndNameMap.size() + " 个，articleAidSet.size()： " + articleAidSet.size());
//                Word.wordOut(saveTable, articleAidSet, rankScore, startYear, top, code, specialist, entry.getKey(), allArticleInfoMap, authAndAuthIdMap, unitOrAuthAndRankMap, authIdAndAuthMap, aIdAndDataInfoMap, ruleMap, tableList, isInsertTable, originalAuthMap);
//                Unit.readUnivTable(saveTable, allArticleInfoMap, nsfcInfoMap, ruleMap, authAndAuthIdMap, aIdAndDataInfoMap, unitOrAuthAndRankMap, articleAidSet, tableList, isInsertTable, originalAuthMap);
//                Unit.readAuthTable(allArticleInfoMap, nsfcInfoMap, ruleMap, authAndAuthIdMap, saveTable, authIdAndAuthMap, aIdAndDataInfoMap, unitOrAuthAndRankMap, articleAidSet, tableList, isInsertTable, originalAuthMap);
//            }
//        }
//
//        long t3 = System.currentTimeMillis();
//        System.out.println(format.format(new Date()) + " 程序全部结束，总用时：" + Utils.Arith.div((t3 - t0), 60000) + " 分钟。");
//
//// main
//    }
//
//
//// end
//}
